package com.ck.list;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CopyOnWriteArrayList;

public class Demo1 {

    private static CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();

    public static void main(String[] args) {
        initData();
        new Thread(() -> {
            test();
        },"1111111111111").start();

        new Thread(() -> {
            test();
        },"2").start();
    }

    private static void initData() {
        for(int i=1;i<=3000;i++) {
            list.add(i);
        }
    }

    private static void test() {
        try {
            FileOutputStream out = new FileOutputStream("D://tmp//test/test"+Thread.currentThread().getId()+".txt");
            for(int i:list){
                String str = i + "\t\n";
                out.write(str.getBytes(StandardCharsets.UTF_8));
            }
            if(out != null) {
                out.flush();
                out.close();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
